package com.controller;

import javax.servlet.annotation.WebListener;
import javax.servlet.http.HttpSessionAttributeListener;
import javax.servlet.http.HttpSessionBindingEvent;
import java.util.Enumeration;

//此监听器只是用来证明FlashMap的处理是用到了session了的
@WebListener
public class MySessionListener implements HttpSessionAttributeListener {
    @Override
    public void attributeAdded(HttpSessionBindingEvent event) {
        Enumeration<String> names = event.getSession().getAttributeNames();
        while (names.hasMoreElements()) {
            System.out.println("added attr name:----" + names.nextElement());
        }
    }

    @Override
    public void attributeRemoved(HttpSessionBindingEvent event) {
        Enumeration<String> names = event.getSession().getAttributeNames();
        while (names.hasMoreElements()) {
            System.out.println("remove attr name:----" + names.nextElement());
        }
    }

    @Override
    public void attributeReplaced(HttpSessionBindingEvent event) {
        Enumeration<String> names = event.getSession().getAttributeNames();
        while (names.hasMoreElements()) {
            System.out.println("replace attr name:----" + names.nextElement());
        }
    }
}
